package com.doubao.notepad_blog_backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doubao.notepad_blog_backend.domain.BmsPost;
import com.doubao.notepad_blog_backend.domain.BmsTag;
import com.doubao.notepad_blog_backend.mapper.BmsTagMapper;
import com.doubao.notepad_blog_backend.service.BmsPostService;
import com.doubao.notepad_blog_backend.service.BmsPostTagService;
import com.doubao.notepad_blog_backend.service.BmsTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

@Slf4j
@Service
public class BmsTagServiceImpl extends ServiceImpl<BmsTagMapper, BmsTag> implements BmsTagService {
    @Resource
    private BmsPostTagService postTagService;
    @Resource
    private BmsPostService postService;

    @Override
    public Page<BmsPost> selectPostsByTagId(Page<BmsPost> postPage, String id) {
        // 获取关联的话题ID
        Set<String> ids =postTagService.getPostIdsByTagId(id);
        LambdaQueryWrapper<BmsPost> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(BmsPost::getId, ids);

        return postService.page(postPage, wrapper);
    }
}
